import HDataTable from "@/components/ant-ext-table/HDataTable";
import HTag from "@/components/ant-ext/HTag";
import {UserStat} from "@/const/const";
import {Avatar, Form} from "antd";
import React from "react";
import {Dispatch} from "redux";
import {HTableProps} from "@/components/ant-ext-table/HTable";
import {useDispatch} from "react-redux";
import EntityUser from "@/api/entity-user";

function getColumns(dispatch: Dispatch): HTableProps<any>["columns"] {
    return [
        {
            title: "ID",
            dataIndex: 'id',
            width: '100px',
            fixed: 'left',

        }, {
            title: "头像",
            dataIndex: 'wxImgUrl',
            render: (v) => {
                return <Avatar size={48} src={v}/>
            }
        }, {
            title: "微信名称",
            dataIndex: 'wxName',
        }, {
            title: "姓名",
            dataIndex: 'idName',
        }, {
            title: "手机",
            dataIndex: 'mobile',
        }, {
            title: "身份证号",
            dataIndex: 'idNo',
        }, {
            title: "状态",
            dataIndex: 'stat',
            render: (value: any) => <HTag value={value} mapping={UserStat.tag}/>
        }, {
            title: "余额",
            dataIndex: 'balance',
        }, {
            title: "冻结金额",
            dataIndex: 'freeze',
        }, {
            title: "总借款金额",
            dataIndex: 'loanAmount',
        }, {
            title: "登陆时间",
            dataIndex: 'loginTime',
        }, {
            title: "注册时间",
            dataIndex: 'regTime',
        }
    ]
}

export default function Index() {
    const [form] = Form.useForm()
    const dispatch = useDispatch()

    return <>
        <HDataTable
            queryForm={{
                form: form,
                item: [
                    {name: "idName", label: "姓名"},
                    {name: "mobile", label: "电话号码"},
                    {name: "stat", label: "状态", type: "select", dataSource: UserStat.select, width: "150px"},
                ]
            }}
            columns={getColumns(dispatch)} selectMethod={EntityUser.selectTablePage}
            rowKey={"id"}
        />
    </>
}